from django.shortcuts import render
from django.http import  HttpResponse
from user.models import UserInfo
import re
# Create your views here.
def register(request):
    return render(request,'index.html',)


def register_past(request):
    print('进入')
    if request.method == 'POST':
        user_name = request.POST.get('username')
        password = request.POST.get('password')
        cpassword = request.POST.get('cpassword')
        emai = request.POST.get('email')

        if not all([user_name, password, cpassword, emai]):
            return render(request, 'index.html')

        if not re.match(r'^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$', emai):
            return render(request, 'index.html')

        user = UserInfo.objects.create_user(username=user_name, email=emai, password=password)
        # create_user(self, username, email=None, password=None,
        user.is_active = 0
        user.save()
        print('提交成功')

        return render(request, 'index.html')
